<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/common.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../css/templet.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../fonts/font-awesome.min.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../mui/css/mui.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../ali/iconfont.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../css/queue.css" />
		<script type="text/javascript" src="../common/js/jquery.js?01_38"></script>

		<!--插件-->
		<script type="text/javascript" src="../common/js/vue.min.js?01_38"></script>
		<script type="text/javascript" src="../common/js/mui.min.js?01_38"></script>
		<script type="text/javascript" src="../common/js/update.js?01_38"></script>

		<script type="text/javascript" src="../common/js/common.js?01_38"></script>
		<script type="text/javascript" src="../common/js/fastclick.js?01_38"></script>
		<script type="text/javascript" src="../common/js/main.js?01_38"></script>
		<script type="text/javascript" src="../common/js/app.js?01_38"></script>
		<style type="text/css">
			.queue_takeNumber .childFooter .footerList.active .bg.bg_01 {
				background-image: url(../images/queue/fb_01.png);
			}
			
			.queue_takeNumber.queue_callNumber .childFooter .footerList.active .bg.bg_02 {
				background-image: url(../images/queue/fb_02.png);
			}
			
			.queue_tableStatus .childFooter .footerList.active .bg.bg_03 {
				background-image: url(../images/queue/fb_03.png);
			}
			
			.queue_takeNumber.queue_callNumber.queue_history .childFooter .footerList.active .bg.bg_04 {
				background-image: url(../images/queue/fb_04.png);
			}
		</style>
	</head>

	<body>
		<!--头部-->
		<header class="bg-red9 fff f-20 pad-t-10 pad-b-10 pad-r-10">
			<div class="pa back pad-l-10 back re" onclick="backpre()">
				<div class="order_back"></div>
				<a></a>
			</div>
			<div class="center header_title"></div>
			<div class="pa set">
				<a onclick="clicked('../queue/queue_set.html')" class="fff f-15 pad-r-10"><i></i></a>
			</div>
		</header>

		<div id="app" v-cloak>
			<div class="mask pa select_pop" v-if="select_pop == 1">
				<div class="pad-l-40 pad-r-40 pad-t-200">
					<div class="bg-fff wrap pr center">
						<div class="fiex pad-20" style="justify-content: space-between; flex-wrap: wrap;">
							<div class="fiex pad-t-20 mag-r-10" v-for="(item,index) in queue_set_list" @click="selectTN(index)">
								<div class="fiex1 mag-r-5">{{item.name}}({{item.count1}}~{{item.count2}})</div>
								<div class="bg" v-bind:class="{ checked:tableChecked == index}"></div>
							</div>
						</div>
						<div class="fiex" style="border-top: 1px solid #e9e9e9;">
							<div class="fiex1 pad-t-15 pad-b-15" @click="cancel()">{{b_lg['1049']}}</div>
							<div class="fiex1 bg-red9 fff pad-t-15 pad-b-15" style="border-bottom-right-radius: 10px;" @click="takeNumber2()">{{b_lg['1008']}}</div>
						</div>
					</div>
				</div>
			</div>
			<template v-if="is_open == 0 && queue_list == ''">
				<div class="no_content center f-14">
					<div class="bg"></div>
					<p>{{b_lg['1435']}}</p>
				</div>
			</template>
			<!--取号-->
			<template v-else>

				<div class="wrap_body queue_takeNumber bg-e4" id="queue_takeNumber" v-if="pageflag == 1 ">

					<!--提示语-->
					<div class="fiex bg-yellow fff hint" v-show="hintflag == 1">
						<div class="pad-12 pad-r-5"><i class="i"></i></div>
						<div class="pad-12 pad-r-5 pad-l-5">{{b_lg['1436']}}</div>
						<div class="fiex1 pad-12 pad-l-5" @click="closeHint()"><i class="close fr"></i></div>
					</div>
					<!--取号内容区-->
					<div class="pad-t-45 pad-b-80" v-if="is_open == 1">
						<!--状态显示-->
						<div class="showBox">
							<div class="pad-l-12 pad-r-12 pad-t-10 cf table_wrap mag-r-10">
								<div class="bg-fff pad-8 pad-b-3 f-12 table center" v-bind:class="{ active:index == isActive }" v-for="(item,index) in queue_set_list" @click="choose($event,index,item.id)">
									<div class="table_info">
										<div class="">{{item.name}}（{{item.count1}}-{{item.count2}}）</div>
										<div class="red9" v-if="item.queue_count"><i class="fa fa-user mag-r-5"></i>{{item.queue_count}}</div>
										<div class="red9" v-else><i class="fa fa-user mag-r-5"></i>0</div>
									</div>
								</div>
							</div>
						</div>
						<div class="pad-t-90">

							<!--个人信息-->
							<div class="bg-fff selfInfo f-15">
								<div class="fiex info active" @click="info(1,$event)">
									<div class="pad-l-12 pad-r-12"><img src="../images/queue/people.png" /></div>
									<div class="left">{{b_lg['1231']}}</div>
									<div class="ccc fiex1 pad-l-12 pad-r-12 fiex">
										<div v-if="form.peop_number.length==0">{{b_lg['1437']}}</div>
										<div class="blue f-24" v-else>{{form.peop_number}}</div>
									</div>
									<div class=" pad-l-12 pad-r-12" @click="clearNum(1)" v-if="form.peop_number != '' "><img src="../images/queue/close2.png" /></div>
								</div>
								<div class="fiex info" @click="info(2,$event)">
									<div class=" pad-l-12 pad-r-12"><img src="../images/queue/phone.png" /></div>
									<div class="left">{{b_lg['1438']}}</div>
									<div class="ccc fiex1 pad-l-12 pad-r-12 fiex">
										<div v-if="form.peop_phone.length==0">{{b_lg['1439']}}</div>
										<div class="blue f-24" v-else>{{form.peop_phone}}</div>
									</div>
									<div class=" pad-l-12 pad-r-12" @click="clearNum(2)" v-if="form.peop_phone != '' "><img src="../images/queue/close2.png" /></div>
								</div>
							</div>

							<!--键盘-->
							<div class="queue_keyboard bg-fff center mag-t-10">
								<div class="number_keyboard fiex f-26">
									<div v-for="(v,k) in num_key" @click="key_down(k+1)" class="number pad-t-10 pad-b-10">{{k+1}}</div>
									<div class="number pad-t-10 pad-b-10" @click="key_down('c')">c</div>
									<div @click="key_down(0)" class="number pad-t-10 pad-b-10">0</div>
									<div class="number pad-t-10 pad-b-10" @click="key_down('d')"><span class="del"></span></div>
								</div>
								<div class="set fiex f-15">
									<div class="fiex2 red9 number pad-t-20 pad-b-20" @click="takeNumber(lianxu,1)" v-if="lianxu>1 && form.peop_number!='' && form.peop_phone == '' ">{{b_lg['1440']}}（{{lianxu}} {{b_lg['1441']}}）</div>
									<div class="fiex2 bg-999 fff number1 pad-t-20 pad-b-20" v-else>{{b_lg['1440']}}（{{lianxu}} {{b_lg['1441']}}）</div>
									<div class="fiex1 bg-999 fff number pad-t-20 pad-b-20" v-if="form.peop_number == '' || form.peop_number == 0">{{b_lg['1434']}}</div>
									<div class="fiex1 bg-red9 fff number pad-t-20 pad-b-20" v-else @click="takeNumber(1,2)">{{b_lg['1434']}}</div>
								</div>
							</div>
						</div>

					</div>
					<div v-else=" is_open == 0">
						<div class="no_content center f-14">
							<div class="bg"></div>
							<p>{{b_lg['1442']}}</p>
						</div>
					</div>

					<!--底部-->
					<div class="childFooter bg-fff pad-l-20 pad-r-20 f-12">
						<div class="fiex childFooterWrap">
							<div class="footerList active pad-t-10" @click="footJum(1)">
								<div class="bg bg_01"></div>
								<div class="center">{{b_lg['1434']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(2)">
								<div class="bg bg_02"></div>
								<div class="center">{{b_lg['1443']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(3)">
								<div class="bg bg_03"></div>
								<div class="center">{{b_lg['1444']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(4)">
								<div class="bg bg_04"></div>
								<div class="center">{{b_lg['1445']}}</div>
							</div>
						</div>
					</div>
				</div>

				<!--叫号-->
				<div class="wrap_body queue_takeNumber queue_callNumber bg-e4" v-else-if="pageflag == 2">

					<!--内容区-->
					<div class="pad-t-45 pad-b-80">

						<div class="have_content">
							<!--状态显示-->
							<div class="showBox">
								<div class="pad-l-12 pad-r-12 pad-t-10 cf table_wrap">

									<div class="bg-fff pad-8 pad-b-3 f-12 table center all" @click="choose($event,0)" v-bind:class="{ active:0 == isActive }">
										<div class="ellipsis-2">{{b_lg['1446']}} </div>
										<div class="red9"><i class="fa fa-user mag-r-5"></i>{{count}}</div>
									</div>
									<div class="bg-fff pad-8 pad-b-3 f-12 table center" @click="choose($event,index+1,item.id)" v-for="(item,index) in queue_set_list" v-bind:class="{ active:index + 1 == isActive }">
										<div class="ellipsis-2">{{item.name}}（{{item.count1}}-{{item.count2}}） </div>
										<div class="red9" v-if="item.queue_count"><i class="fa fa-user mag-r-5"></i>{{item.queue_count}}</div>
										<div class="red9" v-else=""><i class="fa fa-user mag-r-5"></i>0</div>
									</div>
								</div>
							</div>
							<div class="pad-t-90">

								<div class="no_content center f-14" v-if="queue_list.length == 0">
									<div class="bg"></div>
									<p v-if=" is_open == 1 ">{{b_lg['1447']}}</p>
									<p v-else-if=" is_open == 0 ">{{b_lg['1448']}}</p>
								</div>
								<!--状态详情-->
								<div class="table_details_list bg-fff" v-else>
									<div class="fiex table_details" v-for="(value,key,index) in queue_list" v-if="value.status == 1">
										<!--左边号码部分-->
										<div class="fiex2 pad-10" @click="toQueueDetails(value,key)">
											<div class="fiex number">
												<div class="f-30">{{value.letter}}{{value.sn_text}}</div>
												<div class="c666 f-10">（{{value.count}}{{b_lg['1495']}}）</div>
											</div>
											<div class="c666 f-12">{{b_lg['1478']}} <span class="num-addtime">{{parseInt((new Date().getTime() - value.addtime*1000)/1000/60)}}</span> {{b_lg['1259']}}</div>
										</div>
										<!--右边操作部分-->
										<div class="fiex3 pad-10 set_wrap cf center c666">
											<div class="set pad-10 pad-b-5 pr" @click="callNumber(value.q_id,value.sn,key,value)">
												<span class="center fff bg-blue pa f-12 num" v-if="value.times>0">{{value.times}}</span>
												<div class="bg bg_01"></div>
												<p class="f-10">{{b_lg['1443']}}</p>
											</div>
											<div class="set pad-10 pad-b-5" @click="dinner($event,value.q_id,value.sn,key,value)">
												<div class="bg bg_02"></div>
												<p class="f-10">{{b_lg['1449']}}</p>
											</div>
											<div class="set pad-10 pad-b-5" @click="passNumber($event,value.q_id,value.sn,key,value)">
												<div class="bg bg_03"></div>
												<p class="f-10">{{b_lg['1450']}}</p>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>

					</div>
					<div class="hide">
						<div class="no_content center f-14">
							<div class="bg"></div>
							<p>{{b_lg['1442']}}</p>
						</div>
					</div>
					<!--底部-->
					<div class="childFooter bg-fff pad-l-20 pad-r-20 f-12">
						<div class="fiex childFooterWrap">
							<div class="footerList pad-t-10" @click="footJum(1)">
								<div class="bg bg_01"></div>
								<div class="center">{{b_lg['1434']}}</div>
							</div>
							<div class="footerList pad-t-10 active" @click="footJum(2)">
								<div class="bg bg_02"></div>
								<div class="center">{{b_lg['1443']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(3)">
								<div class="bg bg_03"></div>
								<div class="center">{{b_lg['1444']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(4)">
								<div class="bg bg_04"></div>
								<div class="center">{{b_lg['1445']}}</div>
							</div>
						</div>
					</div>
				</div>

				<!--桌台状态-->
				<div class="wrap_body queue_tableStatus bg-e4" v-else-if="pageflag == 3">
					<!--内容部分-->
					<div class="pad-t-45 pad-b-80 f-15">
						<div class="pad-12 pad-t-10 pad-b-2 fiex blue">
							<div class="pad-r-5"><i class="i"></i></div>
							<div class="bg-fff pad-10 sign_block"></div>
							<div class="pad-l-5 pad-r-5">{{b_lg['1451']}}</div>
							<div class="bg-yellow pad-10 sign_block"></div>
							<div class="pad-l-5 pad-r-5">{{b_lg['1452']}}</div>
						</div>
						<div class="pad-l-12 pad-r-12 bg-fff mag-t-10" v-for="(item,index) in table">
							<div class="pad-t-15 pad-b-15 cf" :id="index">
								<div class="fl">{{item.table_cate_name}}</div>
								<div class="fr">{{b_lg['1451']}}<span class="blue pad-l-10">{{item.num}}</span></div>
							</div>
							<!--餐桌状态部分-->
							<div class="cf center table_status">
								<div v-for="(v,i) in item['list']" class="item fl">
									<div class=" bg-yellow pad-10 fff pad-t-5 pad-b-5 mag-b-10 item_content" v-if="v.is_use == '1'">
										<div class="">
											<p class="ellipsis">{{v.table_name}}</p>
											<p><i class="bg mag-r-5"></i>{{v.table_count}}</p>
										</div>
									</div>
									<div class="bg-yellow pad-10 fff pad-t-5 pad-b-5 mag-b-10 empty item_content" v-else-if="v.is_use == '0'">
										<div class="">
											<p class="ellipsis">{{v.table_name}}</p>
											<p><i class="bg mag-r-5"></i>{{v.table_count}}</p>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="hide">
						<div class="no_content center f-14">
							<div class="bg"></div>
							<p>{{b_lg['1442']}}</p>
						</div>
					</div>
					<!--底部-->
					<div class="childFooter bg-fff pad-l-20 pad-r-20 f-12">
						<div class="fiex childFooterWrap">
							<div class="footerList pad-t-10" @click="footJum(1)">
								<div class="bg bg_01"></div>
								<div class="center">{{b_lg['1434']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(2)">
								<div class="bg bg_02"></div>
								<div class="center">{{b_lg['1443']}}</div>
							</div>
							<div class="footerList pad-t-10 active" @click="footJum(3)">
								<div class="bg bg_03"></div>
								<div class="center">{{b_lg['1444']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(4)">
								<div class="bg bg_04"></div>
								<div class="center">{{b_lg['1445']}}</div>
							</div>
						</div>
					</div>
				</div>

				<!--历史-->
				<div class="wrap_body queue_takeNumber queue_callNumber queue_history bg-e4" v-else-if="pageflag == 4">

					<!--内容区-->
					<div class="pad-t-45 pad-b-80">

						<div class="have_content">
							<!--状态显示-->
							<div class="showBox">
								<div class="pad-l-12 pad-r-12 pad-t-10 cf table_wrap">

									<div class="bg-fff pad-8 pad-b-3 f-12 table center all" @click="chooseHistory($event,0,0)" v-bind:class="{ active: isHistoryActive == 0 }">
										<div class="ellipsis-2">{{b_lg['1446']}} </div>
										<div class="red9"><i class="fa fa-user mag-r-5"></i>{{history_count}}</div>
									</div>
									<div class="bg-fff pad-8 pad-b-3 f-12 table center" @click="chooseHistory($event,index+1,item.id)" v-for="(item,index) in history_queue_set_list" v-bind:class="{ active: isHistoryActive == index+1 }">
										<div class="ellipsis-2">{{item.name}} </div>
										<div class="red9">（{{item.count1}}-{{item.count2}}）</div>
									</div>
								</div>
							</div>
							<div class="pad-t-90">

								<div class="no_content center f-14" v-if="history_list.length == 0">
									<div class="bg"></div>
									<p v-if=" is_open == 1 ">{{b_lg['1479']}}</p>
									<p v-else-if=" is_open == 0 ">{{b_lg['1448']}}</p>
								</div>
								<!--状态详情-->
								<div class="table_details_list bg-fff" v-else="">
									<div class="fiex table_details" v-for="(value,key) in history_list">
										<!--v-if="value.status == 2 || value.status == 3"-->
										<!--左边号码部分-->
										<div class="pad-10 pad-l-12 fiex1" @click="toQueueDetails(value,key)">
											<div class="fiex number">
												<div class="f-30">{{value.letter}}{{value.sn_text}}</div>
												<div class="c666 f-10">（{{value.count}}
													<!--{{b_lg['1495']}}-->）
													<span class="eat fff f-10 pad-l-10 pad-r-10 pad-t-2" v-if="value.status == 2">{{b_lg['1453']}}</span>
													<span class="done fff f-10 pad-l-10 pad-r-10 pad-t-2" v-else-if="value.status == 3">{{b_lg['1454']}}</span>
												</div>
											</div>
											<div class="c666 f-12">{{b_lg['1455']}} {{value.addtime}}</div>
										</div>
										<!--右边操作部分-->
										<div class="pad-10 set_wrap fiex center c666 pad-r-12">

											<div class="set pad-10 pad-b-5 mag-r-5" @click="dinnerHistory($event,value.q_id,value.id,value.sn,key,value)" v-if="value.status == 3">
												<div class="bg bg_02"></div>
												<p>{{b_lg['1449']}}</p>
											</div>
											<div class="set pad-10 pad-b-5" @click="revocation(value.id,value.sn,key,value)">
												<div class="bg bg_04"></div>
												<p>{{b_lg['1456']}}</p>
											</div>
										</div>
									</div>
								</div>
								<div class="loading center f-18 mag-b-10" :class="{hide:!isload}">
									<i class="fa fa-spinner fa-pulse"></i>
								</div>
								<!--记录显示完全之后的end-->
								<div class="end end3 center c999 pad-10" :class="{hide:!isend}" v-if="history_list.length > 0">- end -</div>
							</div>
						</div>
					</div>
					<div class="hide">
						<div class="no_content center f-14">
							<div class="bg"></div>
							<p>{{b_lg['1442']}}</p>
						</div>
					</div>
					<!--底部-->
					<div class="childFooter bg-fff pad-l-20 pad-r-20 f-12">
						<div class="fiex childFooterWrap">
							<div class="footerList pad-t-10" @click="footJum(1)">
								<div class="bg bg_01"></div>
								<div class="center">{{b_lg['1434']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(2)">
								<div class="bg bg_02"></div>
								<div class="center">{{b_lg['1443']}}</div>
							</div>
							<div class="footerList pad-t-10" @click="footJum(3)">
								<div class="bg bg_03"></div>
								<div class="center">{{b_lg['1444']}}</div>
							</div>
							<div class="footerList pad-t-10 active" @click="footJum(4)">
								<div class="bg bg_04"></div>
								<div class="center">{{b_lg['1445']}}</div>
							</div>
						</div>
					</div>
				</div>
			</template>

		</div>
	</body>
	<script type="text/javascript">
		//头部返回键
		function backpre() {
			if(isAPP) {
				var preUrl = plus.webview.currentWebview().opener();
				preUrl.evalJS("refresh()");
			}
			com_back();
		}
		//下拉刷新
		function refresh() {
			app.init();
		}
		//webSocket
		function webSocketTn() {
			app.get_stop_queue();
			if(webSocket_stopQueue != null) {
				app.is_open = webSocket_stopQueue.data.is_open;
			} else {
				app.is_open = 999;
			}
			if(app.pageflag == 2) {
				app.get_queue_list(app.queue_id);
			} else if(app.pageflag == 4) {
				app.get_queue_log_list(app.history_id);
			}
		}
		var app = null,
			callNumberTime = "" //取号定时器存贮; 

		function fun1() {

			var table = JSON.parse(getItem("table"));
			var hintflag = getItem("hintflag") ? getItem("hintflag") : 0;
			app = new Vue({
				el: "#app",
				data: {
					table: "",
					b_lg: global_lange, //语言包
					num_key: new Array(9), //数字按键
					tableChecked: 0,
					flag: 1, //键盘
					pageflag: 1, //页码
					hintflag: hintflag, //提示框
					is_open: "", //排队功能是否开启 1开启 0停止
					model: "", //分配方式 1自动 2手动
					queue_set_list: "", //排队分组
					queue_set: "", //排队设置
					queue_list: {}, //排队列表
					code: 1,
					count: "", //全部排队数量
					lianxu: "", //连续取号次数
					table_checked: "", //选中的桌台分类id
					history_table_checked: "", //历史选中的桌台分类id
					isActive: 0, //选择桌台类型部分哪个为选中状态
					isHistoryActive: 0, //历史页选择桌台类型部分哪个为选中状态
					history_count: "", //历史排队总数量
					history_list: {}, //历史列表
					history_queue_set_list: [], //历史排队分组
					form: { //表单提交的数据
						peop_number: "", //用餐人数
						peop_phone: "" //用餐电话
					},
					page: 1, //当前页
					isload: false, //加载的小圆圈是否出现
					isend: false, //数据是否显示完
					total: 0, //总页数
					select_pop: 0,
					queue_id: 0,
					history_id: 0,
					ajaxing: true //请求
				},

				watch: {
					"form.peop_number": function(newVal, oldVal) {
						if(app.model == 1) { //自动分配
							var c1 = null;
							var c2 = null;
							var list = [];
							$.each(app.queue_set_list, function(i, v) {
								c1 = Number(v.count1);
								c2 = Number(v.count2);
								if(newVal >= c1 && newVal <= c2) {
									list = v;
									app.isActive = i;
								}
							});

						}
					}
				},
				mounted: function() {
					var th = this
					var winH = $(window).height(); //屏幕高度
					window.addEventListener('scroll', function(e) { //滚动事件
						domH = $("body").height(); //内容高度
						if((winH + $(window).scrollTop()) > domH - 10) {
							th.getnextpage();
						}
					}, true)
				},
				created: function() {
					this.init();
				},
				methods: {
					init: function() {
						//初始化餐厅接口
						common_ajax(1, {}, "init_shop_info", function(res) {
							if(res.status == 1) {
								$("header .header_title").text(app.b_lg['1434']);
								app.is_open = res.result.queue_set.is_open; //是否开启排队
								app.model = res.result.queue_set.model; //分配方式
								//								app.model = 2;//分配方式
								if(res.result.queue_set_list) {
									res.result.queue_set_list.sort(function(x, y) {
										var x = x.count1,
											y = y.count1;
										if(x == y) {
											return 0;
										}
										return x - y;
									})
								}
								setItem("queue_set_list", JSON.stringify(res.result.queue_set_list));
								queue_set_list = res.result.queue_set_list; //排队分组
								app.queue_set_list = res.result.queue_set_list; //排队分组
								app.lianxu = res.result.queue_set.lianxu; //连续取号次数
								app.form.peop_number = ""; //用餐人数
								app.form.peop_phone = ""; //用餐电话
								if(app.queue_set_list) {
									app.table_checked = app.queue_set_list[0].id; //选中的桌台分类id
								} else {
									app.table_checked = 0;
								}
								app.isActive = 0;
								//设置标题名
								//								app.setTitleName(app.pageflag)
								if(app.pageflag == 1) {
									$(".header_title").text(app.b_lg['1434']);
									$("header .set").show();
								} else if(app.pageflag == 2) {
									$(".header_title").text(app.b_lg['1443']);
									$("header .set").hide();
								} else if(app.pageflag == 3) {
									$(".header_title").text(app.b_lg['1444']);
									$("header .set").hide();
								} else if(app.pageflag == 4) {
									$(".header_title").text(app.b_lg['1445']);
									$("header .set").hide();
								}
								//桌位状态
								common_ajax(1, {}, "get_table_working", function(res) {
									if(res.status == 1) {
										//正在用餐的桌号id
										var table_list_used = [];
										$.each(res.result.list, function(i, v) {
											table_list_used.push(i)
										});
										//全部的桌号id
										var table_list = [];

										$.each(table, function(i, v) {
											var num = 0;
											$.each(v["list"], function(index, value) {
												if(table_list_used.indexOf(value["id"]) == -1) {
													value["is_use"] = 0; //0为未占用
													num++;
												} else {
													value["is_use"] = 1; //1为占用
												}
											});
											v['num'] = num;
										});
										app.table = table;

										//排队列表
										common_ajax(1, {
											"q_id": 0
										}, "get_queue_list", function(res) {
											if(res.status == 1) {
												app.queue_list = res.result.list;
												console.log("app.queue_list", app.queue_list);
												setItem("queue_list", JSON.stringify(res.result.list))
												app.count_list = res.result.count_list;
												var count = 0;
												$.each(app.queue_list, function(i, v) {
													count++;
												});
												app.count = count;
												setItem("cur_all_queue_count", app.count)
												cur_queue_set_list = JSON.parse(getItem("queue_set_list"));
												$.each(app.count_list, function(i, v) {
													var curnum = 0;
													$.each(cur_queue_set_list, function(index, value) {
														if(i == value.id) {
															curnum++;
															value["queue_count"] = v;
														}
													});
												});
												app.queue_set_list = cur_queue_set_list;
												common_ajax(1, {
													"q_id": 0,
													"page": app.page,
													"pagesize": 6
												}, "get_queue_log_list", function(res) {
													var history_queue_set_list = queue_set_list;
													if(res.status == 1) {
														app.total = res.result.total;
														app.history_count = res.result.count;
														app.history_list = res.result.list;
														var cur_queue_set_list = JSON.parse(getItem("queue_set_list"));
														if(app.history_list.length == 0) {
															app.isend = false;
															app.isload = false;
														} else {
															app.get_queue_log_list(); // 初始化
														}
														app.isload = false
														$.each(res.result.count_list, function(i, v) {
															var num = 0;
															$.each(cur_queue_set_list, function(index, value) {
																if(v.q_id == value.id) {
																	value["queue_count"] = v.count;
																}
															});
														});
														app.history_queue_set_list = cur_queue_set_list;
													}

												})
											}
										})
									}
								});
							}
						})

					},
					time_set: function(e) { //重新计算当前时间
 						$(".num-addtime").each(function(){
 							var $th = $(this),
 								num = $th.html();
 							num = Number(num) + 1;
 							$th.html(num)
 							
 						})
					},
					get_stop_queue: function() {
						webSocket_stopQueue = JSON.parse(getItem("webSocket_stopQueue"));
					},
					toQueueDetails: function(v, k) {
						var obj = {};
						obj["k"] = k;
						obj["v"] = v;
						setItem("queue_details", JSON.stringify(obj));
						clicked('../queue/queue_details.html');
					},
					get_queue_list: function(q_id) {
						//						222
						var $th = this;
						common_ajax(1, {
							"q_id": q_id
						}, "get_queue_list", function(res) {
							if(res.status == 1) {
								app.queue_list = res.result.list;
								console.log(res.result.count_list[q_id])
								if(q_id != 0) {
									$.each(app.queue_set_list, function(i, v) {
										console.log(v.id)
										if(v.id == q_id) {
											v.queue_count = res.result.count_list[q_id];
										}
									});
									console.log("app.queue_set_list", app.queue_set_list)
								} else {
									var count = 0;
									app.count_list = res.result.count_list;
									$.each(app.queue_list, function(i, v) {
										count++;
									});
									app.count = count;
									setItem("cur_all_queue_count", app.count)
									cur_queue_set_list = JSON.parse(getItem("queue_set_list"));
									$.each(app.count_list, function(i, v) {
										var curnum = 0;
										$.each(cur_queue_set_list, function(index, value) {
											if(i == value.id) {
												curnum++;
												value["queue_count"] = v;
											}
										});
									});
									app.queue_set_list = cur_queue_set_list;
								}
								var count = 0;
								$.each(app.queue_set_list, function(i, v) {
									if(v.queue_count) {
										count += v.queue_count;
									}
								});
								app.count = count;
								if(q_id == 0) {
									setItem("cur_all_queue_count", app.count);
									cur_queue_set_list = JSON.parse(getItem("queue_set_list"));
									$.each(app.count_list, function(i, v) {
										var curnum = 0;
										$.each(cur_queue_set_list, function(index, value) {
											if(i == value.id) {
												curnum++;
												value["queue_count"] = v;
											}
										});
									});
									app.queue_set_list = cur_queue_set_list;
								}
							}
							clearInterval(callNumberTime);
							callNumberTime = setInterval(function() {
								$th.time_set(app.queue_list)
							}, 60000)
						})

					},
					get_queue_log_list: function(q_id) {
						//加载列表数据
						this.isload = true;
						if(app.page == 1) {
							app.history_list = [];
						}
						common_ajax(1, {
							"q_id": q_id,
							"page": app.page,
							"pagesize": 10
						}, "get_queue_log_list", function(res) {
							if(res.status == 1) { //请求成功
								app.total = res.result.total;
								//								app.history_list = res.result.list;
								$.each(res.result.list, function(i, v) {
									if(app.history_list.indexOf(v) == -1) {
										app.history_list.push(v);
									}
								});
								if(q_id == 0) {
									app.history_count = res.result.count;
									//									var cur_queue_set_list = JSON.parse(getItem("queue_set_list"));
									//									$.each(res.result.count_list, function(i,v) {
									//										var num = 0;
									//										$.each(cur_queue_set_list, function(index,value) {
									//											if (v.q_id == value.id) {
									//												value["queue_count"] = v.count;
									//											}
									//										});
									//									});
									//									app.history_queue_set_list = cur_queue_set_list;
								}
								app.isend = false;
								app.isload = false;
								app.ajaxing = true;
								if(app.history_list.length == 0) {
									app.isload = false;
									app.isend = false;
								}
							} else {
								mui.toast(res.msg);
							}
						})
					},
					getnextpage: function() { //获取下一页数据
						if(this.ajaxing) {
							this.ajaxing = false;
							var curpage = this.page; //赋值给中间变量
							curpage++;
							if(curpage <= this.total) { //如果当前页码小于等于总页码才会加载数据
								this.page = curpage;
								this.get_queue_log_list();
							} else {
								app.isload = false;
								app.isend = true;
							}
						}
					},
					key_down: function(e) {
						var n = null;
						if(app.flag == 1) {
							n = app.form.peop_number;
						} else {
							n = app.form.peop_phone;
						}
						switch(e) {
							case "c":
								n = "";
								break;
							case "d":
								n = n.substr(0, n.length - 1)
								break;
							default:
								n += e;
								break;
						}
						if(app.flag == 1) {
							app.form.peop_number = n.substring(0, 2);
						} else {
							app.form.peop_phone = n.substring(0, 11);
						}

					},
					gotoart: function(e) {
						clicked(e)
					},
					//输入框高亮显示
					info: function(n, ele) {
						app.flag = n;
						_this = ele.currentTarget;
						$(_this).addClass("active").siblings().removeClass("active")
					},
					//关闭提示框
					closeHint: function() {
						app.hintflag = 0;
						setItem("hintflag", app.hintflag)
					},
					//清除输入框内容
					clearNum: function(n) {
						if(n == 1) {
							app.form.peop_number = "";
						} else {
							app.form.peop_phone = ""
						}
					},
					//设置标题名
					setTitleName: function(num) {
						if(num == 1) {
							$(".header_title").text(app.b_lg['1434']);
							app.isActive = 0;
							app.get_queue_list(app.queue_id);
						} else if(num == 2) {
							$(".header_title").text(app.b_lg['1443']);
							app.isActive = 0;
							app.queue_id = 0;
							this.get_queue_list(app.queue_id);
						} else if(num == 3) {
							$(".header_title").text(app.b_lg['1444']);
						} else if(num == 4) {
							$(".header_title").text(app.b_lg['1445']);
							app.isHistoryActive = 0;
							app.history_id = 0;
							app.get_queue_log_list(app.history_id);
						}
					},
					footJum: function(e) {
						if(e!=2) clearInterval(callNumberTime); //如果点击的不是叫号界面则取消刷新的刷新时间的定时器
						app.pageflag = e;
						setItem("pageflag", e)
						//设置标题名
						app.setTitleName(e)
					},
					//叫号选择桌子分类
					choose: function(ele, index, id) {
						var $th = this;
						app.isActive = index;
						if(index == 0) {
							app.queue_id = 0;
						} else {
							app.queue_id = id;
						}
						if($th.pageflag != 1) { //如果是区号页面则不调用当前分类下的列表
							app.get_queue_list(id);
						}
					},
					//历史选择桌子分类
					chooseHistory: function(ele, index, id) {
						app.isHistoryActive = index;
						if(index == 0) {
							app.history_id = 0;
						} else {
							app.history_id = id;
						}
						app.page = 1;
						app.get_queue_log_list(id);
					},
					//叫号
					callNumber: function(id, sn, k, v) {
						var list = {};
						$.each(app.queue_list, function(index, value) {
							if(value.q_id == id) {
								list[index] = value;
							}
						});
						var num = 0;
						var str = "";
						$.each(list, function(i, v) {
							if(i > Number(k) && v.openid) {
								str = str + "," + v.sn;
								num++;
								if(num >= 3) {
									return false;
								}
							}
						}); //
						str = str.substr(1, str.length);
						common_ajax(1, {
							"q_id": id,
							"sn": sn,
							"sn_list": str
						}, "call_queue", function(res) {
							if(res.status == 1) {
								//排队列表

								//音频播放器
								var objauiod = {}, //声音对象
									arrauido = [], //声音数组
									auidoch = "?001" //清除缓存
								function auidoplays(arr) {
									var lgsrc = "../audio/"; //路径
									//匹配语言
									switch(getItem("lg")) {
										case "zh":
											lgsrc += "zh/";
											break;
										case "en":
											lgsrc += "en/";
											break;
										default:
											lgsrc += "en/";
											break;
									}
									//暂停原有音频
									$.each(arrauido, function(i, v) {
										objauiod[i].pause();
									});
									arrauido = []; //清空
									objauiod = {}; //清空
									//音频播放
									//arrauido=[lgsrc+"dingdong.mp3","../audio/a.mp3","../audio/b.mp3","../audio/c.mp3","../audio/yongcan.mp3"];
									//插入叮咚
									arrauido.push(lgsrc + "dingdong.mp3" + auidoch);
									//插入字母
									var ens = arr.letter.toLowerCase();
									arrauido.push(lgsrc + ens + ".mp3" + auidoch);
									//遍历插入数字
									var arrs = arr.sn_text.split("");
									$.each(arrs, function(i, v) {
										arrauido.push(lgsrc + v + ".mp3" + auidoch);
									});
									//插入请用餐；
									arrauido.push(lgsrc + "yongcan.mp3" + auidoch);

									//载入对象
									$.each(arrauido, function(i, v) {
										objauiod[i] = new Audio(v);
									});
									//遍历监听播放下一个
									$.each(arrauido, function(i, v) {
										if(i < arrauido.length) {
											objauiod[i].addEventListener("ended", function() {
												if(objauiod[i + 1] != undefined) {
													objauiod[i + 1].play();
												}
											})
										}
									});
									objauiod[0].play(); //播放数组里第一个音频
								}

								auidoplays(v)

								app.get_queue_list(app.queue_id);
								_th = "";
							} else {
								mui.toast(res.msg)
							}
						})

					},
					//用餐
					dinner: function(ele, id, sn, k, v) {
						var btnArray3 = [app.b_lg['1049'], app.b_lg['1008']];
						mui.confirm(app.b_lg['1480'], app.b_lg['1320'], btnArray3, function(ee) {
							if(ee.index == 1) {
								//确定
								common_ajax(1, {
									"q_id": id,
									"sn": sn,
									"status": 2
								}, "set_queue", function(res) {
									if(res.status == 1) {
										app.get_queue_list(app.queue_id);
										app.get_queue_log_list(app.history_id);
										//										app.get_queue_list(app.isActive);
										//										app.history_count ++;
										//										app.init();
										mui.toast(v.letter + v.sn_text + app.b_lg['1481'])
									}
								})
							}
						}, "div")
					},
					dinnerHistory: function(ele, q_id, id, sn, k, v) {
						var btnArray2 = [app.b_lg['1049'], app.b_lg['1008']];
						mui.confirm(app.b_lg['1480'], app.b_lg['1320'], btnArray2, function(ee) {
							if(ee.index == 1) {
								//确定
								common_ajax(1, {
									"id": id,
									"sn": sn
								}, "put_queue_log_eating", function(res) {
									if(res.status == 1) {
										//排队列表k;
										app.get_queue_log_list(app.history_id);
										app.get_queue_list(app.queue_id);
										//										app.get_queue_log_list(app.isHistoryActive)
										//										app.init();
										mui.toast(v.letter + v.sn_text + app.b_lg['1481'])

									}
								})
							}
						}, "div")

					},
					//过号
					passNumber: function(ele, id, sn, k, v) {
						var btnArray2 = [app.b_lg['1049'], app.b_lg['1008']];
						mui.confirm(app.b_lg['1482'] + " " + v.letter + v.sn_text + " " + app.b_lg['1483'], app.b_lg['1320'], btnArray2, function(ee) {
							if(ee.index == 1) {
								//确定
								common_ajax(1, {
									"q_id": id,
									"sn": sn,
									"status": 3
								}, "set_queue", function(res) {
									if(res.status == 1) {
										//排队列表
										app.get_queue_list(app.queue_id);
										app.get_queue_log_list(app.history_id);
										//app.init();
										mui.toast(v.letter + v.sn_text + app.b_lg['1454'])
									}
								})
							}
						}, "div")

					},
					//撤销
					revocation: function(id, sn, k, v) {
						var btnArray2 = [app.b_lg['1049'], app.b_lg['1008']];
						mui.confirm(app.b_lg['1482'] + " " + v.letter + v.sn_text + " " + app.b_lg['1484'], app.b_lg['1320'], btnArray2, function(ee) {
							if(ee.index == 1) {
								//确定
								common_ajax(1, {
									"id": id
								}, "put_queue_log_recall", function(res) {
									if(res.status == 1) {

										app.get_queue_log_list(app.history_id);
										app.get_queue_list(app.queue_id);
										//										app.history_count --;
										//										app.init();
										mui.toast(v.letter + v.sn_text + app.b_lg['1485'])
									}
								})
							}
						}, "div")

					},
					//取号
					takeNumber: function(n, c) {
						//times:连续取号次数

						if(app.model == 1) { //自动
							app.takeNumber2(n);
						} else { //手动
							app.select_pop = 1;
							app.code = c;
						}
					},
					takeNumber2: function(num) {
						var list = app.queue_set_list[app.isActive];
						if(app.model == 2) {
							if(app.code == 1) {
								num = app.lianxu;
							} else {
								num = 1;
							}
						}
						common_ajax(1, {
							"q_id": list.id,
							"letter": list.letter,
							"count": app.form.peop_number,
							"mobile": app.form.peop_phone,
							"number": num
						}, "put_queue", function(res) {
							if(res.status == 1) {
								app.init();
								mui.toast(app.b_lg['1486']);
								app.select_pop = 0;
							} else {
								mui.toast(res.msg);
							}
						})
					},
					selectTN: function(i) { //取号时弹出框里的选择桌类
						app.tableChecked = i;
					},
					cancel: function() {
						app.select_pop = 0;
					}
				}
			})
		}
	</script>

</html>
